import Vue from 'vue'
import moment from 'moment'

Vue.filter('HMS', time => {
    return moment(time).format('HH:mm:ss')
})
Vue.filter('YMDHMS', time => {
    if (time) {
        return moment(time).format('YYYY-MM-DD HH:mm:ss')
    } else {
        return ''
    }
})

Vue.filter('YMD', time => {
    if (time) {
        return moment(time).format('YYYY-MM-DD')
    } else {
        return ''
    }
})

Vue.filter('AGE', time => {
    if (time) {
        const timeStamp = new Date(time).valueOf()
        const now = new Date().valueOf()
        const gap = now - timeStamp;
        const age = Math.ceil(gap/(1000*60*60*24*365))
        return age
    } else {
        return ''
    }
    
})

Vue.filter('CNY', (s, type) => {
    function formatDecimal(num, decimal) {
        num = num ? num.toString() : '0'
        let index = num.indexOf('.')
        if (index !== -1) {
          num = num.substring(0, decimal + index + 1)
        } else {
          num = num.substring(0)
        }
        return parseFloat(num).toFixed(decimal)
      }
    return '￥' + formatDecimal(s,2)
})

Vue.filter('PERCENT', (num) => {
    if (num) {
        return (Math.round(num * 10000)/100).toFixed(2) + '%'
    } else {
        return '0.00%'
    }
})

/**select+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
Vue.prototype.console = window.console;
Vue.prototype.GLOBAL = {
    sexOptionList: [
        { text: '男', value: 1 },
        { text: '女', value: 2 },
    ],
    autoFlagOptionList: [
        { text: '自动', value: 1 },
        { text: '手动', value: 0 }
    ],
    interventionStatusOptionList: [
        { text: '待执行', value: 0 },
        { text: '已执行', value: 1 },
        { text: '执行失败', value: 2 },
        { text: '已取消', value: 3 },
    ],
    evaluationTypeOptionList: [
        { text: '糖尿病健康评估', value: 'TNBPC' },
        { text: '高血压风险评估', value: 'GXYPC' },
        { text: '高血脂风险评估', value: 'GXZPC' },
        { text: '痛风风险评估', value: 'TFPC' },
        { text: '慢阻肺病风险评估', value: 'MXZSXFBCP' },
        { text: '三高风险评估', value: 'SGPC' },
    ]
}